import { action, computed, observable } from 'mobx';
import { Tools } from 'weaver-mobile';
import { Browser, BrowserHrm, ListPage, RouteLayout, SelectPage } from 'weaver-mobile-page';

const getLabel = Tools.getLabel;
// const RouteStore = RouteLayout.Store;

export default class Store extends RouteLayout.Store {
  @observable valueSpan1 = [];
  @observable valueSpan2 = [];
  @observable valueSpan3 = [];
  @observable valueArray = [];
  @observable valueArrayType = ['3'];
  @observable valueArrayLevel = ['0'];
  @observable layout = null;
  @observable selectPage = null;
  @observable list = new ListPage.Store();
  @observable browser3 = new Browser.Store();
  @observable browser2 = new Browser.Store();
  @observable browser6 = new Browser.Store();
  @observable browser7 = new Browser.Store();
  @observable browser4 = new Browser.Store();
  @observable browserHrm = new BrowserHrm.Store();
  @observable replaceDataItem = {};
  @observable browserValue3 = [];
  @observable browserValue2 = [];
  @observable browserValue6 = [];
  @observable browserValue4 = [];
  @observable browserHrmValue = [];
  @observable seclevel = [0, 100];
  @observable browserValue = [];
  @observable browserLevelValue = [];
  @observable isShowSecLevel = true; // 控制显示安全级别
  // @observable ids = '';

  @action
  initLayout = (route) => {
    this.layout = new RouteLayout.Store({ route });
    this.selectPage = new SelectPage.Store({ route: this.layout.path });
    this.selectPage2 = new SelectPage.Store({ route: this.layout.path });
    this.browserHrm = new BrowserHrm.Store({ route: this.layout.path });
    this.browser3 = new Browser.Store({ route: this.layout.path });
    this.browser2 = new Browser.Store({ route: this.layout.path });
    this.browser6 = new Browser.Store({ route: this.layout.path });
    this.browser4 = new Browser.Store({ route: this.layout.path });
    this.browser7 = new Browser.Store({ route: this.layout.path });
  }

  @computed get ids() {
    const jobfield = [];
    this.valueArray.map((item) => {
      if (item.sharetype === '6') {
        jobfield.push(item.jobfield);
      } else {
        jobfield.push(item.relatedshare);
      }
    });
    return jobfield.join();
  }

  @computed get valueSpan() {
    const array = [];
    this.valueArray.map((item) => {
      const str = this.getValueSpan(item, this.isShowSecLevel);
      array.push(str);
    });
    return array;
  }

  getValueSpan = (item, isShowSecLevel = true) => {
    let str = '';
    if (item && item.sharetype) {
      let seclevel = '';
      if (isShowSecLevel) {
        seclevel = `${getLabel(683, '安全级别')}${getLabel(30586, '为')}${item.seclevel}${getLabel(18946, '的')}`;
      } else if (item.sharetype !== '5') {
        seclevel = `${getLabel(18946, '的')}`;
      }
      switch (item.sharetype) {
        case '3':
        case '2':
          str = `${item.sharetypespan}(${item.relatedsharespan})${seclevel}` +
            `${item.sharetypespan}${getLabel(125212, '成员')}`;
          break;
        case '5':
          str = `${seclevel}${item.sharetypespan}`;
          break;
        case '1':
          str = `${getLabel(131394, '人员')}(${item.relatedsharespan})`;
          break;
        case '4':
          str = `${item.sharetypespan}(${item.relatedsharespan})${getLabel(3005, '共享级别')}` +
            `=${item.rolelevelspan}${seclevel}${item.sharetypespan}${getLabel(125212, '成员')}`;
          break;
        case '6':
          str = `${item.sharetypespan}(${item.relatedsharespan}/` +
            `${item.joblevelspan}${item.jobfieldspan ? `(${item.jobfieldspan})` : ')'}`;
          break;
        default:
          break;
      }
    }
    return str;
  }

  @action setBrowserValue(type, value) {
    switch (type) {
      case '3':
        this.browserValue3 = value;
        break;
      case '2':
        this.browserValue2 = value;
        break;
      case '1':
        this.browserHrmValue = value;
        break;
      case '4':
        this.browserValue4 = value;
        break;
      case '6':
        this.browserValue6 = value;
        break;
      default:
        break;
    }
  }
}
